Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | import io from 'socket.io-client' import { useState, useEffect } from 'react' import { useRouter } from 'next/router' import { FiCopy, FiEye, FiEyeOff } from 'react-icons/fi' import { RiVipCrownFill } from 'react-icons/ri' import { TbDoorExit } from 'react-icons/tb' import { BiArrowToRight } from 'react-icons/bi' import dojoDomains from '../../lib/dojoDomains' let socket export default function Room() { const router = useRouter() const room = router.query.room const user = router.query.user const domain = router.query.domain const [roomData, setRoomData] = useState() const [hide, setHide] = useState(true) const [timer, setTimer] = useState(30) const [timerStarted, setTimerStarted] = useState(false) useEffect(() => { socketInitializer() }, []) useEffect(() => { let interval if (timerStarted) { interval = setInterval(() => { if (timer <= 1) { setTimerStarted(false) clearInterval(interval) } socket.emit('update-timer', { room, timer }) }, 1000) } return () => clearInterval(interval) }, [timerStarted, timer]) const socketInitializer = async () => { await fetch('/api/socket') socket = io() socket.emit('join-room', { room, user, domain }) socket.on('room-data', (roomData) => { setRoomData(roomData) }) socket.on('hide-from-server', (hide) => { setHide(hide) }) socket.on('update-timer-from-server', (timer) => { setTimer(timer) }) } function handlePrincipleBtnClick(n) { let principles = Object.keys(dojoDomains[domain]) let i = principles.indexOf(roomData.principle) let newPrinciple = principles[Math.min(principles.length - 1, Math.max(0, i + n))] socket.emit('set-principle', { room, newPrinciple }) } function handleCardClick(colour) { socket.emit('select-belt-colour', { room, colour }) } function handleHideClick() { socket.emit('hide-cards', { room, hide: !hide }) } function handleClearCards() { socket.emit('clear-cards', { room }) } function handleTimerClick() { if (timerStarted) { setTimerStarted(false) } setTimerStarted(true) socket.emit('update-timer', { room, timer: 31 }) } function handleLeaveRoomClick() { socket.emit('leave-room', { room }) router.push('/rooms') } function handleChatSubmit(e) { e.preventDefault() let msg = e.target.elements.chat.value if (msg) { socket.emit('chat-message', { room, msg }) e.target.elements.chat.value = '' } } return ( <div className="max-w-6xl mx-auto p-10"> <h1 className="text-2xl text-blue-800 mb-10 capitalize"> Domain: {roomData?.domain} </h1> <div className="mb-10 border-2"> <div className="bg-lightPeriwinkle p-2 flex justify-between"> <h2 className="text-xl">{roomData?.principle}</h2> {roomData && roomData?.connections?.[socket?.id]?.admin && ( <div className="flex gap-5"> {roomData && roomData?.connections?.[socket?.id]?.admin && Object.keys(dojoDomains[domain]).indexOf(roomData.principle) > 0 && ( <button onClick={() => handlePrincipleBtnClick(-1)} className="bg-periwinkle text-white px-2 py-1 rounded-xl hover:bg-darkPeriwinkle" > Previous Principle </button> )} {roomData && roomData?.connections?.[socket?.id]?.admin && Object.keys(dojoDomains[domain]).indexOf(roomData.principle) < Object.keys(dojoDomains[domain]).length - 1 && ( <button onClick={() => handlePrincipleBtnClick(1)} className="bg-periwinkle text-white px-2 py-1 rounded-xl hover:bg-darkPeriwinkle" > Next Principle </button> )} </div> )} </div> <div className="flex gap-10 mt-5 px-5"> <div className="font-bold">Digital Dojo Practices:</div> <ul className="list-disc list-inside"> {roomData && dojoDomains?.[roomData?.domain]?.[ roomData?.principle ]?.practices.map((e, i) => <li key={i}>{e}</li>)} </ul> </div> <div className="space-y-5 p-5"> {roomData && Object.entries( dojoDomains?.[roomData?.domain]?.[roomData?.principle]?.belts ).map(([belt, qualities], i) => ( <div key={belt + i} className="flex gap-5 items-center"> <div> <img src={`/${belt}_poker_belt.png`} alt={`/${belt} poker belt`} className="w-20 rounded-lg border-2 p-1 shadow-lg" /> </div> <ul className="list-disc list-inside rounded-lg border-2 border-black px-5 py-2 shadow-lg w-full"> {qualities.map((quality, i) => ( <li key={quality + i} className="w-full"> {quality} </li> ))} </ul> </div> ))} </div> </div> <div className="md:flex gap-5"> <div className="md:w-2/3 mb-5"> <div className="flex justify-between"> <button onClick={() => handleCardClick('white')} className="w-24 h-32 px-4 border-2 rounded shadow-lg hover:scale-105 duration-200" aria-label="white poker belt select" > <img src="/white_poker_belt.png" alt="white poker belt"></img> </button> <button onClick={() => handleCardClick('yellow')} className="w-24 h-32 px-4 border-2 rounded shadow-lg hover:scale-105 duration-200" aria-label="yellow poker belt select" > <img src="/yellow_poker_belt.png" alt="yellow poker belt"></img> </button> <button onClick={() => handleCardClick('green')} className="w-24 h-32 px-4 border-2 rounded shadow-lg hover:scale-105 duration-200" aria-label="green poker belt select" > <img src="/green_poker_belt.png" alt="green poker belt"></img> </button> <button onClick={() => handleCardClick('black')} className="w-24 h-32 px-4 border-2 rounded shadow-lg hover:scale-105 duration-200" aria-label="black poker belt select" > <img src="/black_poker_belt.png" alt="black poker belt"></img> </button> <button onClick={() => handleCardClick('na')} className="w-24 h-32 px-4 border-2 rounded shadow-lg hover:scale-105 duration-200" aria-label="unknown belt select" > <img src="/na_poker_belt.png" alt="unknown poker belt"></img> </button> </div> <div className="mt-7 flex justify-center gap-10"> {roomData?.connections?.[socket?.id]?.admin && ( <> <button onClick={handleHideClick} className="px-2 rounded bg-periwinkle text-white hover:bg-darkPeriwinkle" > Hide </button> <button onClick={handleClearCards} className="px-2 rounded bg-periwinkle text-white hover:bg-darkPeriwinkle" > Clear </button> </> )} </div> <div className="my-5 flex justify-between font-bold text-periwinkle"> <p>Users</p> <div className="flex items-center gap-2"> {hide ? <FiEyeOff /> : <FiEye />} <p>Card</p> </div> </div> <div className="space-y-3"> {roomData && Object.entries(roomData?.connections).map(([k, v]) => ( <div key={k} className="flex justify-between shadow-lg h-16 rounded text-white" > <div className={`${ socket?.id === k ? 'bg-periwinkle text-white' : 'text-black' } flex items-center px-2 rounded-tl rounded-bl border-r border-periwinkle min-w-[75px]`} > {v.user} {v.admin ? ( <RiVipCrownFill className={`ml-2 text-sm ${ socket?.id === k ? 'text-white' : 'text-periwinkle' }`} /> ) : ( '' )} </div> <div className={`flex items-center w-12 h-14 p-2 mr-1 my-auto mx-auto justify-center border-2 border-darkPeriwinkle text-black ${ v.belt ? '' : 'border-dashed' }`} > {!v.belt ? ( '' ) : socket?.id !== k && hide ? ( <img src="/card_back.JPG" alt={`${v.belt} belt`}></img> ) : ( <img src={`/${v.belt}_poker_belt.png`}></img> )} </div> </div> ))} </div> </div> <aside className="flex flex-col border md:w-1/3"> <div> <p className="bg-lightPeriwinkle p-3 font-bold"> Room Code: <button title="copy room code" onClick={() => navigator.clipboard.writeText(room)} className="font-semibold float-right relative mr-2 hover:text-darkPeriwinkle" > {room} <FiCopy className="absolute -top-2 -right-4" /> </button> </p> <p className="p-3 font-bold text-periwinkle"> Players Name: <span className="font-bold float-right">{user}</span> </p> <p className="p-3 font-bold text-periwinkle"> Players Online: <span className="font-bold float-right"> {roomData && Object.keys(roomData?.connections).length} </span> </p> <div className="my-5 flex justify-between p-3"> <p className="font-bold text-periwinkle">Timer:</p> <div className="flex gap-2 ml-auto"> {roomData && roomData?.connections?.[socket?.id]?.admin && ( <button onClick={handleTimerClick} className="px-2 rounded bg-periwinkle text-white hover:bg-darkPeriwinkle" > Timer </button> )} <div className={`${ timer < 10 ? 'text-red-700' : 'text-periwinkle' } border-2 w-10 px-1 text-right`} > :{('0' + timer).slice(-2)} </div> </div> </div> <div className="flex items-start justify-center"> <button onClick={handleLeaveRoomClick} className="bg-periwinkle text-white hover:bg-darkPeriwinkle rounded px-2 py-1 flex items-center gap-2" > Leave Room <TbDoorExit /> </button> </div> </div> <div> <p className="bg-lightPeriwinkle font-bold p-3 mt-5">Chat Room</p> <div className="min-h-[300px] max-h-[300px] overflow-y-scroll mt-2"> {roomData && roomData.chat.map((e, i) => ( <> <p className={`px-1 text-sm mx-2 font-bold ${ e.id === socket?.id ? 'text-right' : '' }`} > {roomData.connections?.[e.id]?.user}: </p> <p key={i} className={`px-2 text-sm rounded bg-lightPeriwinkle mx-2 mb-2 break-words ${ e.id === socket?.id ? 'text-right' : '' }`} > {e.msg} </p> </> ))} </div> <form onSubmit={handleChatSubmit} className="flex items-center justify-center" > <div className="flex w-full"> <label htmlFor="chat" hidden> chat box </label> <input id="chat" name="chat" className="text-periwinkle flex-1 px-2 p-1 border border-periwinkle" placeholder="Write a message" /> <button className="bg-periwinkle text-white w-8" aria-label="submit chat message" > <BiArrowToRight className="text-center mx-auto" /> </button> </div> </form> </div> </aside> </div> </div> ) } export async function getServerSideProps({ locale }) { /* istanbul ignore next */ const langToggleLink = locale === 'en' ? '/fr/rooms' : '/rooms' /* Place-holder Meta Data Props */ const meta = { data_en: { title: 'Digital Dojo - Rooms', desc: 'English', author: '', keywords: '', }, data_fr: { title: 'Dojo Numérique - Rooms', desc: 'Français', author: '', keywords: '', }, } return { props: { locale, langToggleLink, meta }, } } |